package cn.ecut.service.impl;


import cn.ecut.dao.XiangmuDao;
import cn.ecut.model.Xiangmu;
import cn.ecut.model.Yuangong;
import cn.ecut.service.XiangmuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

@Service
public class XiangmuServiceimpl implements XiangmuService {
    @Autowired
    private XiangmuDao xiangmuDao;

    @Override
    public int insert(Xiangmu xinamu) {
        return xiangmuDao.insert(xinamu);
    }

    @Override
    public String getxiangmuBianma() {
        DecimalFormat decimalFormat=new DecimalFormat("00000");
        String s = xiangmuDao.selectThelast();
        s=s.substring(2);
        System.out.println(s);
        int i=Integer.parseInt(s)+1;
        String k=decimalFormat.format(i);
        String xiangmuBianma = "XM"+k;
        System.out.println(xiangmuBianma);
        return xiangmuBianma;
    }

    @Override
    public Object getXiangmuMessage() {
        HashMap<String, Object> map = new HashMap<String, Object>();
        Integer count = xiangmuDao.selectAllcount();
        List<Xiangmu> list = new ArrayList();
        list=xiangmuDao.selectAll();
        map.put("code", 0);
        map.put("msg", "");
        map.put("count", count);
        map.put("data", list);//dao层查询返回list数据
        return map;
    }

    @Override
    public int updateQiyong(Xiangmu xiangmu) {
        return xiangmuDao.updateQiyong(xiangmu);
    }

    @Override
    public List<Xiangmu> advanceSelect(String s) {
        return xiangmuDao.advanceSelect(s);
    }

    @Override
    public int deletexiangmu(String xiangmubianma) {
        xiangmuDao.deletetaofang(xiangmuDao.selectfangjian(xiangmubianma));
        xiangmuDao.deletefangjian(xiangmubianma);
        xiangmuDao.deletetaofang(xiangmubianma);
        xiangmuDao.deleteloudong(xiangmubianma);
        xiangmuDao.deleteByPrimaryKey(xiangmubianma);
        return 1;
    }

    @Override
    public int updateByPrimaryKey(Xiangmu xiangmu) {
        return xiangmuDao.updateByPrimaryKey(xiangmu);
    }
}
